package com.rjwh.dingdong.client.mvp.presenter.impl;

import android.content.Context;

import com.aishua.lib.task.AsResult;
import com.rjwh.dingdong.client.bean.jsonbean.ResGetRadioAnchorHomePageBean;
import com.rjwh.dingdong.client.bean.localbean.GetRadioAnchorHomePageBean;
import com.rjwh.dingdong.client.bean.localbean.RadioAnchorInfo;
import com.rjwh.dingdong.client.bean.localbean.RadioPageAlbumData;
import com.rjwh.dingdong.client.constant.NetConstant;
import com.rjwh.dingdong.client.mvp.BasePresenter;
import com.rjwh.dingdong.client.mvp.model.impl.RadioAnchorHomePageModel;
import com.rjwh.dingdong.client.mvp.presenter.IRadioAnchorHomePagePresenter;
import com.rjwh.dingdong.client.mvp.view.RadioAnchorHomePageView;

import java.util.List;

/**
 * @author Kay
 * @ClassName RadioAnchorHomePagePresenter
 * @Description
 * @date 2016-11-17
 * @history 2016-11-17 author: description:
 */

public class RadioAnchorHomePagePresenter extends BasePresenter<RadioAnchorHomePageView> implements IRadioAnchorHomePagePresenter {

    private RadioAnchorHomePageModel model;

    public RadioAnchorHomePagePresenter(Context context, RadioAnchorHomePageView mMvpView) {
        super(context, mMvpView);
        model = new RadioAnchorHomePageModel(this);
    }

    @Override
    public void onServerDataAcquired(int businessType, AsResult mAsResult, boolean isRefresh) {
        if (getMvpView() != null) {
            getMvpView().hideLoadingView();
            switch (businessType) {
                case NetConstant.GETRADIODATA:
                    ResGetRadioAnchorHomePageBean resGetRadioAnchorHomePageBean = (ResGetRadioAnchorHomePageBean) mAsResult.getObj();
                    if (mAsResult.getResultCode() > NetConstant.MSG_CONNECT_SUCCESS && resGetRadioAnchorHomePageBean != null && resGetRadioAnchorHomePageBean.getData() != null) {
                        getMvpView().hideErrorView();
                        GetRadioAnchorHomePageBean data = resGetRadioAnchorHomePageBean.getData();
                        RadioAnchorInfo basicinfo = data.getBasicinfo();
                        List<RadioPageAlbumData> albumlist = data.getAlbumlist();

                        if (basicinfo != null && albumlist != null) {
                            getMvpView().loadData(basicinfo, albumlist);
                        } else {
                            getMvpView().showErrorView();
                        }
                    } else {
                        getMvpView().showErrorView();
                    }
                    break;
                default:
                    break;
            }
        }
    }

    @Override
    public void detachView() {
        model.detachView();
        detachViews();
    }

    /**
     * 获取主播主页
     *
     * @param radioid 主播id
     */
    @Override
    public void doGetAnchorHomePage(String radioid) {
        if (isViewAttached()) {
            getMvpView().hideErrorView();
            getMvpView().showLoadingView();
            model.doGetAnchorHomePage(radioid);
        }
    }
}
